package com.refactor.demo;

import java.util.Objects;

public class Rental {

	/**
	 * 电影类型
	 */
	private Movie movie;

	/**
	 * 租借天数
	 */
	private int dayRented;

	private MovieStrategy strategy;

	public Movie getMovie() {
		return movie;
	}

	public void setMovie(Movie movie) {
		this.movie = movie;
		MovieTypeEnums en = MovieTypeEnums.getInstance(movie.getTypeCode());
		switch (Objects.requireNonNull(en)){
			case CHILDREN:
				strategy = new ChildrenMovie();
				break;
			case NEW_RELEASE:
				strategy = new NewReleaseMovie();
				break;
			case REGULAR:
				strategy = new RegularMovie();
				break;
		}
	}

	public int getDayRented() {
		return dayRented;
	}

	public void setDayRented(int dayRented) {
		this.dayRented = dayRented;
	}

	public Rental(Movie movie, int dayRented) {
		this.setMovie(movie);
		this.dayRented = dayRented;
	}

	public Rental() {
	}

	/**
	 * 获取价格
	 * @return
	 */
	public double getCharge(){
		if(strategy == null){
			throw new IllegalArgumentException("参数异常");
		}
		return strategy.getCharge(dayRented);
	}


	/**
	 * 获取积分
	 * @return
	 */
	public int getIntegralPoints(){
		if(strategy == null){
			throw new IllegalArgumentException("参数异常");
		}
		return strategy.getIntegralPoints(dayRented);
	}
}
